package com.sjr.easy.chat.app.utils;

import com.alibaba.fastjson2.JSON;
import com.sjr.easy.chat.business.BusinessNoBusiness;
import com.sjr.easy.chat.business.SequenceNumBusiness;
import com.sjr.easy.chat.dto.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class SequenceUtils {

    @Autowired
    private BusinessNoBusiness businessNoBusiness;

    @Autowired
    private SequenceNumBusiness sequenceNumBusiness;


    public Long genUserCode() {
        Result<Long> userCodeResult = businessNoBusiness.genBusinessNo("easy_chat", "user_code");
        log.info("userCodeResult:{}", JSON.toJSONString(userCodeResult));
        return userCodeResult.getData();
    }

    /**
     * 生成用户头像文件名
     *
     * @return
     */
    public Long genUserPortraitName() {
        Result<Long> userPortraitResult = businessNoBusiness.genBusinessNo("easy_chat", "user_portrait");
        log.info("userPortraitResult:{}", JSON.toJSONString(userPortraitResult));
        return userPortraitResult.getData();
    }


    /**
     * 生成inbox消息ID
     *
     * @return
     */
    public Long genInboxMessageId() {
        Result<Long> result = sequenceNumBusiness.genId("easy_chat", "inbox_message_id");
        log.info("result:{}", JSON.toJSONString(result));
        return result.getData();
    }


    /**
     * 生成outbox消息ID
     *
     * @return
     */
    public Long genOutboxMessageId() {
        Result<Long> result = sequenceNumBusiness.genId("easy_chat", "outbox_message_id");
        log.info("result:{}", JSON.toJSONString(result));
        return result.getData();
    }
    /**
     * 生成outbox消息ID
     *
     * @return
     */
    public Long genChatGroupCode() {
        Result<Long> result = sequenceNumBusiness.genId("easy_chat", "chat_group_code");
        log.info("result:{}", JSON.toJSONString(result));
        return result.getData();
    }
}
